/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author freis
 */
@WebServlet(name = "ControllerServlet", loadOnStartup = 1,
            urlPatterns = {"/cpanel",
                            "/authenticate"})
public class ControllerServlet extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String userPath = request.getServletPath();
        String url;
        
        if (userPath.equals("/cpanel")) {
           
            url = "/WEB-INF/view/panel" + userPath + ".jsp";
            renderPage(url, request, response);
        }

        
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String userPath = request.getServletPath();
        String url;
        
        if (userPath.equals("/authenticate")) {
            
            response.sendRedirect("cpanel");
        }

    }
    
    private void renderPage(String url, HttpServletRequest request, HttpServletResponse response){
        try {
            if(url != null) {
                request.getRequestDispatcher(url).forward(request, response);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
    private int getAdministrationLevel(HttpServletRequest request, HttpServletResponse response){
        return 0;
    }

}
